export default function ajax(opt) {
        opt = opt || {};
        opt.method = opt.method || 'GET';
        opt.url = opt.url || '';
        opt.async = opt.async || true;
        opt.data = opt.data || null;
        opt.success = opt.success || function () {};
         var xmlHttp = null;
         if (XMLHttpRequest) {
             xmlHttp = new XMLHttpRequest();
         }
         else {
             xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
         }
         var params = [];
         for (var key in opt.data){
             params.push(key + '=' + opt.data[key]);
         }
         var postData = params.join('&');
         var attch=''
         if(postData){
            attch=postData+'&rd='+Date.now()
        }else{
            attch='rd='+Date.now()
        }
         var meth=opt.method.toUpperCase()
         if (meth === 'POST') {
             xmlHttp.open(meth, opt.url, opt.async);
             xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
             xmlHttp.send(postData);
         }
         else{
            if(opt.url.indexOf('?')>-1){
                opt.url=opt.url+'&'+attch
            }else{
              opt.url=opt.url+'?'+attch
            }
             xmlHttp.open(meth, opt.url, opt.async);
             xmlHttp.send(null);
         }
         xmlHttp.onreadystatechange = function () {
             if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                var data
                if(typeof xmlHttp.responseText==='string'){
                    data=JSON.parse(xmlHttp.responseText)
                }else{
                    data=xmlHttp.responseText
                }
                 opt.success(data);
             }
         };
     }
